#ifndef ____Format_H____
#define ____Format_H____

#include <string>
#include <vector>
#include <boost/any.hpp>

class CItem
{
public:
  typedef enum _EType : unsigned char
  {
    E_Unknown,
    E_Char,
    E_UnsignedChar,
    E_Short,
    E_UnsignedShort,
    E_Int,
    E_UnsignedInt,
    E_LongLong,
    E_UnsignedLongLong,
    E_Float,
    E_Double,
    E_Chars,
    E_Raw,
    E_Bit,
  } EType;
  EType type;
  unsigned short length;
  std::string name;
  std::string unit;
  boost::any value;
};

typedef std::vector<CItem> VItem;

class CFormat
{
public:
  CFormat() {};
  ~CFormat() {};

  void load(const std::string &strXml);
  void print() const;
  void encode(std::vector<unsigned char> &data) const;
  bool decode(const std::vector<unsigned char> &data);
  bool decode(const unsigned char *p, int nSize);

  const boost::any &get(int index);
  const boost::any &get(const std::string &name);
  bool set(int index, const boost::any &v);
  bool set(const std::string &name, const boost::any &v);
  inline size_t size() { return m_vItems.size(); }
  inline bool isEmpty() { return m_vItems.size() == 0; }
  inline bool isValid() { return m_vItems.size() > 0; }
  inline const VItem &get() const { return m_vItems; }
  inline VItem &get() { return m_vItems; }

private:
  VItem m_vItems;
};

#endif // ____Format_H____
